package com.vint.mi;

/**
 * 1. easy
 * 2. done
 * 大数相减
 */
public class Mi3 {

    private static String solution(String line){
        String[] src = line.split("-");
        return delStr(src[0].trim(),src[1].trim());
    }
    public static String delStr(String str1, String str2){
        int length1 = str1.length();
        int length2 = str2.length();
        if(length1<length2) {
            return delStr(str2, str1);
        }
        if(str1.equals(str2)){
            return "0";
        }
        char[] s1 = str1.toCharArray();
        char[] s2 = str2.toCharArray();
        StringBuffer sb = new StringBuffer();

        int i,j;
        int carry = 0;
        for(i = length1 - 1, j = length2 - 1; j >= 0; i--,j--){
            if(s1[i] + carry >= s2[j]){
                sb.append(String.valueOf(s1[i]-s2[j]+carry));
                carry = 0;
            }else{
                sb.append(String.valueOf(s1[i]-s2[j]+carry+10));
                carry = -1;
            }
        }
        for(i = length1 - length2 - 1; i >= 0; i--){
            if(s1[i] + carry >= 0){
                sb.append(String.valueOf(s1[i]+carry-'0'));
                carry = 0;
            }else{
                sb.append(String.valueOf(9));
                carry = -1;
            }
        }
        return sb.reverse().toString();
    }
    public static void main(String[] args) {
        String ex1 = "22222222234 - 2222212";
        System.out.println(solution(ex1));
        String ex2 = "1231231237812739878951331231231237812739878951331231231237812739878951331231231237812739878951331231231237812739878951331231231237812739870 - 89513312312312378127398789513312312312378127398789513312312312378127398789513";
        System.out.println(solution(ex2));

    }
}
